const request = require('./request')

const BASE_URL = '/finance/record'

/**
 * 首页基本参数
 * @returns 
 */
function indexInitParam(param) {
  return request.get(BASE_URL + '/index/init', param)
}

/**
 * 记账基本参数
 * @returns 
 */
function writeInitParam() {
  return request.get(BASE_URL + '/write/init')
}

/**
 * 音频录音分析
 * @param {*} param 
 * @returns 
 */
function audioRecordRecognition(param) {
  // 这里用POST方式，参数放body
  return request.post(BASE_URL + '/audio/record/recognition', { content: param.content, type: param.type })
}

/**
 * 消费小票识别
 * @param {*} param 
 * @returns 
 */
function consumeTipRecognition(param) {
  // 这里用POST方式，参数放body
  return request.post(BASE_URL + '/ticket/tip/recognition', { content: param.content, type: param.type })
}

/**
 * 账单截图识别
 * @param {*} param 
 * @returns 
 */
function screenshotRecognition(param) {
  // 这里用POST方式，参数放body
  return request.post(BASE_URL + '/screenshot/recognition', { content: param.content, type: param.type })
}

/**
 * 保存或修改前缀检查
 * @param {*} param 
 * @returns 
 */
function recordBeforeCheck(param) {
  // 这里用POST方式，参数放body
  return request.post(BASE_URL + '/before/check', param)
}

/**
 * 保存记账记录
 * @param {*} param 
 * @returns 
 */
function saveFinanceRecord(param) {
  // 这里用POST方式，参数放body
  return request.post(BASE_URL + '/save', param)
}

/**
 * 修改记账记录
 * @param {*} recordId 记录id 
 * @param {*} param 
 * @returns 
 */
function editFinanceRecord(recordId, param) {
  return request.put(BASE_URL + '/edit/'+ recordId, param)
}

/**
 * 删除记账记录
 * @param {*} recordId 记录id 
 * @param {*} param 
 * @returns 
 */
function deleteFinanceRecord(recordId) {
  return request.delete(BASE_URL + '/logic/delete/'+ recordId)
}

/**
 * 根据记录id获取记账记录的明细列表
 * @param {*} recordId 记录id 
 * @param {*} param 
 * @returns 
 */
function getFinanceRecordItemList(recordId) {
  return request.get(BASE_URL + '/item/'+ recordId)
}

/**
 * 获取本人记账最新的记录（不区分账户）
 * @param {*} number 
 * @returns 
 */
function getTopFinanceRecordList(param) {
  return request.get(BASE_URL + '/top/record', param)
}

/**
 * 获取记账详情
 * @param {*} recordId 记录id 
 * @returns 
 */
function getFinanceRecordDetail(recordId) {
  return request.get(BASE_URL + '/detail/'+ recordId)
}

/**
 * 分页搜索记账记录
 * @param {*} param 搜索参数
 * @returns 
 */
function searchRecordPageList(param) {
  return request.get(BASE_URL + '/search/page/list', param)
}

/**
 * 分页日历搜索记账记录
 * @param {*} param 搜索参数
 * @returns 
 */
function searchCalendarInit(param) {
  return request.get(BASE_URL + '/search/calendar/init', param)
}

/**
 * 分页日历搜索某天的记账记录
 * @param {*} param 搜索参数
 * @returns 
 */
function searchCalendarDay(param) {
  return request.get(BASE_URL + '/search/calendar/date', param)
}

/**
 * 拆分记账记录
 * @param {*} financeId 记账id
 * @returns 
 */
function splitRecord(financeId) {
  return request.post(BASE_URL + '/split/'+ financeId)
}

/**
 * 获取拆分列表
 * @param {*} financeId 记账id
 * @returns 
 */
function splitResult(financeId) {
  return request.get(BASE_URL + '/split/'+ financeId + "/result")
}

/**
 * 分页查询记账图库记录
 * @param {*} param 搜索参数
 * @returns 
 */
function galleryPageList(current = 1, size = 10) {
  return request.get(BASE_URL + '/gallery/page/list', { 
    current, size 
  })
}

module.exports = {
  indexInitParam,
  audioRecordRecognition,
  consumeTipRecognition,
  screenshotRecognition,
  writeInitParam,
  recordBeforeCheck,
  saveFinanceRecord,
  editFinanceRecord,
  deleteFinanceRecord,
  getFinanceRecordItemList,
  getTopFinanceRecordList,
  getFinanceRecordDetail,
  searchRecordPageList,
  searchCalendarInit,
  searchCalendarDay,
  splitRecord,
  splitResult,
  galleryPageList
}; 